package com.njxzc.igo.controller.products;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.njxzc.igo.model.Seller;
import com.njxzc.igo.service.GoodsService;
import com.njxzc.igo.service.GoodsServiceImpl;
import com.njxzc.igo.utils.ShoppingResult;

import net.sf.json.JSONObject;


@WebServlet(name="AddNewProducts",urlPatterns="/savenewProduct.do" )
public class ADealAddNewProducts extends HttpServlet{

	private GoodsService gs  = new GoodsServiceImpl();
		protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
				PrintWriter out = response.getWriter();
				int productTypeId = Integer.parseInt((String) request.getAttribute("typeId"));
				String productName = (String) request.getAttribute("productName");
				String productImgAdd = (String) request.getAttribute("productImgAdd");
				String details = (String)  request.getAttribute("details");
				String description = (String)  request.getAttribute("desciption");
				int price = Integer.parseInt((String) request.getAttribute("price"));
				int amount = Integer.parseInt((String) request.getAttribute("amount"));
				int saleAmount = Integer.parseInt((String) request.getAttribute("saleAmount"));
				String salername =  (String) request.getAttribute("saler");
				//add
				Seller saler = gs.findSalerBysalerName(salername);
				ShoppingResult rs = gs.addnewProductByType( productTypeId, productName, productImgAdd, details, description, price, amount, saleAmount, saler);
				JSONObject jo = JSONObject.fromObject(rs);
				out.println(jo.toString());
		}
		
}
